use "${clean}analysis.dta", clear
keep if north == 1 
drop if congress > 55
drop if state == "District of Columbia"

//standardizing variables
egen birth_county_surban = std(birth_county_urban_percent)
egen birth_county_srugged = std(birth_county_ruggedness)
egen birth_county_spostoffice = std(birth_county_postoffice_area)
egen sborn = std(born)

// creating a variable to keep the sample constant
cap drop sample
gen sample = 1
foreach var of varlist $county_bcontrols $life_controls {
	replace sample = . if `var' == .
}
keep if sample == 1

// dropping third parties
drop if partyid == 2 | partyid == .


// dropping WHIGS
replace partyid = . if party_name == "Whig"
replace partyid = 1 if bioguide == "B000376"
replace partyid = 1 if bioguide == "S000261"
replace partyid = 1 if bioguide == "S000801"


// creating some variables
local c = 1860

gen period = year > `c'
replace year = year - `c'



// estimates
estimates clear
eststo: mixed singular c.year##i.period##ib1.partyid  if sample == 1 || _all:R.congress || bioguide_id:
eststo: mixed singular c.year##i.period##ib1.partyid  ${county_bcontrols} ${life_controls} if sample == 1 || _all:R.congress || bioguide_id:

	
// long version for appendix
esttab est* using "${output}TabD5_congress_NDNR_fulltable.tex", replace ///
	b(%8.3f) se(%8.3f) transform(ln*: exp(@) exp(@)) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	keep( ///
		year ///
		1.period  ///
		0.partyid ///
		1.period#c.year ///
		0.partyid#c.year ///
		1.period#0.partyid ///
		1.period#0.partyid#c.year ///
		birth_county_surban birth_county_spostoffice birth_county_srugged birth_county_anyriver birth_county_anycanal ///
		sborn college usmilitary ///
		_cons) ///
	order( ///
		year ///
		1.period  ///
		0.partyid ///
		1.period#c.year ///
		0.partyid#c.year ///
		1.period#0.partyid ///
		1.period#0.partyid#c.year ///
		birth_county_surban birth_county_spostoffice birth_county_srugged birth_county_anyriver birth_county_anycanal ///
		sborn college usmilitary ///
		_cons) ///
	coeflabels( ///
		year "Year of Speech" ///
		1.period "After 1860" ///
		0.partyid "Democrat" ///
		1.period#c.year "After 1860 $\times$ Year of Speech" ///
		0.partyid#c.year "Democrat $\times$ Year of Speech" ///
		1.period#0.partyid "After 1860 $\times$ Democrat" ///
		1.period#0.partyid#c.year "After 1860 $\times$ Democrat $\times$ Year of Speech" ///
		birth_county_surban "County of Birth: \% Urban (std)" /// 
		birth_county_spostoffice "County of Birth: Post Office Density (std)" ///
		birth_county_srugged "County of Birth: Terrain Ruggedness (std)" ///
		birth_county_anyriver "Born on River" ///
		birth_county_anycanal "Born on Canal" ///
		sborn "Year of Birth (std)" ///
		college "Attended College" ///
		usmilitary "Served in US Military" ///
		_cons "Constant" ///
		) ///
	nodepvars nomtitles nonotes ///
	eqlabels("" "sd(Congress)" "sd(Bioguide)" "sd(Residual)", none) ///
	nogaps nolines posthead(\midrule) prefoot(\midrule) postfoot("\bottomrule \end{tabular}}") ///
	tex compress	

